<?php
/**
 * @link https://www.leadshop.vip/
 * @copyright Copyright ©2020-2021 浙江禾成云计算有限公司
 */

namespace store\models;

use framework\common\CommonModels;
use sizeg\jwt\Jwt;
use Yii;
use yii\web\UnauthorizedHttpException;
use \framework\common\TokenHttpException;

/**
 * This is the model class for table "{{%store}}".
 *
 * @property integer $id
 * @property string $store_name
 * @property string $store_rename
 * @property int|null $created_time
 */

class Store extends CommonModels
{

    const id           = ['key' => 20, 'unique', 'comment' => 'ID'];
    const store_name     = ['varchar' => 30, 'notNull', 'comment' => '店铺全称'];
    const store_rename     = ['varchar' => 100, 'Null', 'comment' => '商家简称'];
    const store_address         = ['varchar' => 255,'notNull', 'comment' => '地区'];
    const store_state       = ['int' => 1,'Null', 'comment' => '店铺状态，0关闭，1开启，2审核中	'];
    const store_close_info       = ['varchar' => 50,'Null', 'comment' => '店铺关闭原因'];
    const store_sort       = ['int' => 11, 'Null','default' => 0, 'comment' => '店铺排序'];
    const store_logo       = ['varchar' => 255, 'comment' => '店铺logo'];
    const store_banner    = ['varchar' => 255, 'Null', 'comment' => '店铺横幅'];
    const store_avatar       = ['varchar' => 150, 'Null', 'comment' => '店铺头像'];
    const seo_keywords       = ['varchar' => 255, 'Null', 'comment' => '店铺seo关键字'];
    const seo_description    = ['varchar' => 255, 'Null', 'comment' => '店铺seo描述'];
    const store_phone        = ['varchar' => 11 , 'Null', 'comment' => '商家电话'];
    const store_zy       = ['text' => '','Null', 'comment' => '主营商品'];
    const store_recommend    = ['tinyint' => 1, 'Null', 'default' => 0,'comment' => '推荐，0为否，1为是，默认为0'];
    const store_sales       = ['int' => 10, 'Null','default' => 0, 'comment' => '店铺销量'];
    const work_start_time       = ['varchar' => 50, 'Null','default' => '09:00', 'comment' => '每天营业开始时间'];
    const is_own_shop    = ['tinyint' => 3, 'Null', 'default' => 0,'comment' => '是否自营店铺 1是 0否'];
    const deleted   = ['tinyint' => 1, 'default' => 0, 'comment' => '删除状态'];
    const deleted_time = ['int' => 11, 'comment' => '删除时间'];
    const work_end_time       = ['varchar' => 50, 'Null','default' => '18:00', 'comment' => '每天营业结束时间，-号表示次日时间'];
    const business_licence_cert   = ['varchar' => 150, 'Null', 'comment' => '店铺头像'];
    const legal_person       = ['varchar' => 255, 'Null', 'comment' => '店铺seo关键字'];
    const legal_identity    = ['varchar' => 255, 'Null', 'comment' => '店铺seo描述'];
    const business_date        = ['varchar' => 11 , 'Null', 'comment' => '商家电话'];
    const business_scope        = ['varchar' => 11 , 'Null', 'comment' => '商家电话'];
    const business_licence_number        = ['varchar' => 11 , 'Null', 'comment' => '商家电话'];
    const created_time = ['bigint' => 10, 'comment' => '创建时间'];
    const updated_time = ['bigint' => 10, 'comment' => '修改时间'];
    const user_id       = ['int' => 10, 'Null','default' => 0, 'comment' => '關聯員工ID'];



    public function scenarios()
    {
        $scenarios            = parent::scenarios();
        $scenarios['create']  = ['store_name', 'store_rename', 'store_address','store_phone','description', 'work_end_time', 'work_start_time', 'user_id'];
        $scenarios['update']  = ['store_name', 'store_rename', 'store_address','store_phone','description', 'work_end_time', 'work_start_time', 'user_id'];

        return $scenarios;
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%store}}';
    }

    /**
     * 增加额外属性
     * @return [type] [description]
     */
    public function attributes()
    {
        $attributes = parent::attributes();
        return $attributes;
    }



    /**
     * 用户行为信息
     * @return [type] [description]
     */
//    public function getUser()
//    {
//        return $this->hasOne($this->modelClass(), ['store_id' => 'store_id']);
//    }

    public static function findIdentity($id)
    {
        return static::findOne($id);
    }

}
